import keyboard
from bdtime import tt
import json


def _send_one_line(line, send_all=False, interval=0.1):
    k1 = 'shift + enter' if send_all else 'enter'
    keyboard.press_and_release(k1)

    tt.sleep(interval)
    keyboard.write(line)

    keyboard.press_and_release('enter')


def send_str_ls(str_ls, send_all=True, interval_1=0.5, interval_2=0.1, interval_3=0.25):
    tt.sleep(interval_1)

    for ls in str_ls:
        if tt.stop_alt():
            break

        line = ' '.join(ls)
        _send_one_line(line, send_all=send_all, interval=interval_2)
        tt.sleep(interval_3)

        # _send_one_line('□' * len(line), send_all=send_all, interval=interval_2)


def main():
    output_file = 'tempdir/20_False_11_170.txt'
    # with open(output_file, 'r') as f:
    #     str_ls = json.load(f)
    # with open(output_file, 'r', encoding='utf-8') as f:
    #     ss = f.read()
    # str_ls = [list(s) for s in ss.split('\n')]

    from .text_to_image import read_str_ls
    str_ls = read_str_ls(output_file)
    send_str_ls(str_ls)


if __name__ == '__main__':
    main()

    # from tools.text_to_image import show_str_ls
    # show_str_ls(str_ls)


